package lrz.shiftplanner.calendar;
 


public class ShiftSlots {

	
	/* ShiftSlot manages the right number of shift types according to
	 * the day type
	 */
	
	class ShiftSlot {
		private int shiftCount;
		private int shiftCapacity;
		private ShiftType shiftType;
	}

	private ShiftSlot slots[];
	private int[] validSlots;
	
	public ShiftSlots(DayType type) {
		slots = new ShiftSlot[ShiftType.values().length];
		validSlots = new int[DayType.getShiftTypeNumber(type)];
		int k=0;
		for (int i=0;i<ShiftType.values().length;i++) {
			slots[i] = new ShiftSlot();
			slots[i].shiftCount = 0;
			slots[i].shiftType = ShiftType.values()[i];
			slots[i].shiftCapacity = DayType.getShiftCount(type, slots[i].shiftType);
			if (slots[i].shiftCapacity>0 && i<ShiftType.values().length-1)
				validSlots[k++] = i;
		}
	}
	
	
	public int getDelta(ShiftType shiftType) {
		return slots[shiftType.ordinal()].shiftCount - slots[shiftType.ordinal()].shiftCapacity;
	}
	
	public int getCount(ShiftType shiftType) {
		return slots[shiftType.ordinal()].shiftCount;
	}
	
	public int getCapacity(ShiftType shiftType) {
		return slots[shiftType.ordinal()].shiftCapacity;
	}
	
	public int[] getValidSlots() {
		return validSlots;
	}
	
	public int[] getDeltas() {
		int[] deltas = new int[ShiftType.values().length];
		for (int i=0;i<deltas.length;i++)
			deltas[i] = getDelta(ShiftType.values()[i]);
		return deltas;
	}
	
	public void changeCount(ShiftType shiftType, int delta) {
		slots[shiftType.ordinal()].shiftCount+=delta;
	}
	
	public void changeCount(ShiftType shiftType1, int delta1, ShiftType shiftType2, int delta2) {
		slots[shiftType1.ordinal()].shiftCount+=delta1;
		slots[shiftType2.ordinal()].shiftCount+=delta2;
	}
	
	public void changeDayType(DayType type) {
		int k=0;
		validSlots = new int[DayType.getShiftTypeNumber(type)];
		for (int i=0;i<ShiftType.values().length;i++) {
			slots[i].shiftCapacity = DayType.getShiftCount(type, slots[i].shiftType);
			if (slots[i].shiftCapacity>0 && i<ShiftType.values().length-1)
				validSlots[k++] = i;
		}
	}
	
	
	
}



